import Vue from 'vue'
import Router from 'vue-router'
import MapPage from './../components/MapPage'
import indexPage from './../components/indexPage'
import indexPage1 from './../components/indexPage1'
import Moint from './../components/Moint'
import RainMonitor from './../components/RainMonitor'
import App from './../App'
// import ReportExport from './../components/page/reportExport/ReportExport'
// import SewagePlantData from './../components/page/reportExport/SewagePlantData'
import Login from './../components/page/login/Login'
import Page404 from './../components/page/404'
import Page500 from './../components/page/500'

Vue.use(Router)

/**
 * 定义vue路由
 */
const router = new Router({
  routes: [
    // { // 测试路由
    //   path: '/test',
    //   component: Test,
    //   meta: {
    //     title: '测试页面',
    //     skipLoginCheck: true // 该路由跳过登陆检查
    //   }
    // },
    {
      path: '/', redirect: '/App'
    },
    {
      path: '/App',
      component: App,
      // 默认打开地图
      redirect: '/App/indexPage',
      // redirect: '/App/indexPage1',
      // 子页面
      children: [
        // 地图页面
        {
          path: 'MapPage',
          component: MapPage
          // meta: {allowBack: false}
        },
        {
          path: 'indexPage',
          component: indexPage
          // meta: {allowBack: false}
        },
        {
          path: 'indexPage1',
          component: indexPage1
          // meta: {allowBack: false}
        },
        {
          path: 'Moint',
          component: Moint
          // meta: {allowBack: false}
        },
        // 雨量
        // {
        //   path: 'RainMonitor',
        //   component: RainMonitor
        // },
        // 报表导出页面
        // {
        //   path: 'ReportExport',
        //   component: ReportExport
        // },
        // {
        //   path: 'SewagePlantData',
        //   component: SewagePlantData
        // },

        // 500界面
        {
          path: '500',
          component: Page500,
          meta: {
            title: '服务器内部错误',
            skipLoginCheck: true // 该路由跳过登陆检查
          }
        }
      ]
    },
    // 500界面
    {
      path: '/500',
      component: Page500,
      meta: {
        title: '服务器内部错误',
        skipLoginCheck: true // 该路由跳过登陆检查
      }
    },
    // 登陆界面
    {
      path: '/Login',
      component: Login,
      meta: {
        title: '用户登陆',
        skipLoginCheck: true // 该路由跳过登陆检查
      }
    },
    // 当以上路径都不能匹配上时则进入404
    {
      path: '*',
      component: Page404,
      name: 'notfound',
      meta: {
        title: '404-页面丢了',
        skipLoginCheck: true // 该路由跳过登陆检查
      }
    }
  ]
})
// let allowBack = true //    给个默认值true
// if (to.meta.allowBack !== undefined) {
//   allowBack = to.meta.allowBack
// }
// if (!allowBack) {
//   history.pushState(null, null, location.href)
// }
// store.dispatch('updateAppSetting', {
//   allowBack: allowBack
// })

// 前端路由拦截器（导航守卫）逻辑
// router.beforeEach((to, from, next) => {
//   let { fullPath, meta: { skipLoginCheck } } = to
//   const { $notify } = Vue.prototype
//   // 是跳过登陆的场合
//   if (skipLoginCheck) {
//     next()
//     return
//   }
//   // 检查token
//   if (typeof localStorage['user_login_token'] !== 'string' || localStorage['user_login_token'] === '') {
//     next({
//       path: '/Login',
//       query: {redirect: fullPath} // 将跳转的路由path作为参数，登录成功后跳转到该路由
//     })
//     $notify.error({
//       title: '错误',
//       message: '尚未登陆！'
//     })
//     return
//   }
//   let life = parseInt(localStorage['user_login_life'])
//   // 检查token是否过期
//   if (Number.isNaN(life) || life < new Date().getTime()) {
//     next({
//       path: '/Login',
//       query: {redirect: fullPath} // 将跳转的路由path作为参数，登录成功后跳转到该路由
//     })
//     $notify.error({
//       title: '错误',
//       message: '登陆已经过期！'
//     })
//     return
//   }
//   // 放行
//   next()
// })

export default router
